home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d945.lha / Reminder / src / src.lha / RemDICE.c < prev    next >
C/C++ Source or Header  |  1993-04-19  |  12KB  |  390 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Matti Rintala
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "RemDICE.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = "Workbench";
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *MainWnd = NULL;
  31. struct Gadget         *MainGList = NULL;
  32. struct IntuiMessage    MainMsg;
  33. struct Gadget         *MainGadgets[21];
  34. UWORD                  MainLeft = 0;
  35. UWORD                  MainTop = 0;
  36. UWORD                  MainWidth = 632;
  37. UWORD                  MainHeight = 187;
  38. UBYTE                 *MainWdt = (UBYTE *)"Reminder V1.20 © 1993 Matti Rintala";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *MainFont = NULL;
  43.  
  44. UBYTE *ARexxMode0Labels[] = {
  45.     (UBYTE *)"Not_hing",
  46.     (UBYTE *)"Scr_ipt",
  47.     (UBYTE *)"_Command",
  48.     NULL };
  49.  
  50. extern struct MinList Weekday0List;
  51.  
  52. struct Node Weekday0Nodes[] = {
  53.     &Weekday0Nodes[1], ( struct Node * )&Weekday0List.mlh_Head, 0, 0, "Monday",
  54.     &Weekday0Nodes[2], &Weekday0Nodes[0], 0, 0, "Tuesday",
  55.     &Weekday0Nodes[3], &Weekday0Nodes[1], 0, 0, "Wednesday",
  56.     &Weekday0Nodes[4], &Weekday0Nodes[2], 0, 0, "Thursday",
  57.     &Weekday0Nodes[5], &Weekday0Nodes[3], 0, 0, "Friday",
  58.     &Weekday0Nodes[6], &Weekday0Nodes[4], 0, 0, "Saturday",
  59.     &Weekday0Nodes[7], &Weekday0Nodes[5], 0, 0, "Sunday",
  60.     ( struct Node * )&Weekday0List.mlh_Tail, &Weekday0Nodes[6], 0, 0, "ANY" };
  61.  
  62. struct MinList Weekday0List = {
  63.     ( struct MinNode * )&Weekday0Nodes[0], ( struct MinNode * )NULL, ( struct MinNode * )&Weekday0Nodes[7] };
  64.  
  65. extern struct MinList MonthList0List;
  66.  
  67. struct Node MonthList0Nodes[] = {
  68.     &MonthList0Nodes[1], ( struct Node * )&MonthList0List.mlh_Head, 0, 0, "January",
  69.     &MonthList0Nodes[2], &MonthList0Nodes[0], 0, 0, "February",
  70.     &MonthList0Nodes[3], &MonthList0Nodes[1], 0, 0, "March",
  71.     &MonthList0Nodes[4], &MonthList0Nodes[2], 0, 0, "April",
  72.     &MonthList0Nodes[5], &MonthList0Nodes[3], 0, 0, "May",
  73.     &MonthList0Nodes[6], &MonthList0Nodes[4], 0, 0, "June",
  74.     &MonthList0Nodes[7], &MonthList0Nodes[5], 0, 0, "July",
  75.     &MonthList0Nodes[8], &MonthList0Nodes[6], 0, 0, "August",
  76.     &MonthList0Nodes[9], &MonthList0Nodes[7], 0, 0, "September",
  77.     &MonthList0Nodes[10], &MonthList0Nodes[8], 0, 0, "October",
  78.     &MonthList0Nodes[11], &MonthList0Nodes[9], 0, 0, "November",
  79.     &MonthList0Nodes[12], &MonthList0Nodes[10], 0, 0, "December",
  80.     ( struct Node * )&MonthList0List.mlh_Tail, &MonthList0Nodes[11], 0, 0, "ANY" };
  81.  
  82. struct MinList MonthList0List = {
  83.     ( struct MinNode * )&MonthList0Nodes[0], ( struct MinNode * )NULL, ( struct MinNode * )&MonthList0Nodes[12] };
  84.  
  85. struct IntuiText MainIText[] = {
  86.     2, 0, JAM1,487, 53, NULL, (UBYTE *)"Remind # days before and after:", NULL,
  87.     2, 0, JAM1,451, 94, NULL, (UBYTE *)"Date of event:", NULL,
  88.     2, 0, JAM1,425, 10, NULL, (UBYTE *)"ARexx:", NULL };
  89.  
  90. #define Main_TNUM 3
  91.  
  92. UWORD MainGTypes[] = {
  93.     LISTVIEW_KIND,
  94.     CHECKBOX_KIND,
  95.     LISTVIEW_KIND,
  96.     BUTTON_KIND,
  97.     BUTTON_KIND,
  98.     BUTTON_KIND,
  99.     BUTTON_KIND,
  100.     BUTTON_KIND,
  101.     TEXT_KIND,
  102.     MX_KIND,
  103.     BUTTON_KIND,
  104.     STRING_KIND,
  105.     LISTVIEW_KIND,
  106.     INTEGER_KIND,
  107.     INTEGER_KIND,
  108.     INTEGER_KIND,
  109.     STRING_KIND,
  110.     STRING_KIND,
  111.     STRING_KIND,
  112.     INTEGER_KIND,
  113.     CHECKBOX_KIND
  114. };
  115.  
  116. struct NewGadget MainNGad[] = {
  117.     286, 99, 105, 56, (UBYTE *)"_Weekday", NULL, GD_Weekday, PLACETEXT_BELOW, NULL, (APTR)WeekdayClicked,
  118.     571, 73, 26, 11, (UBYTE *)"D_elete event when acked", NULL, GD_Autodelete, PLACETEXT_LEFT, NULL, (APTR)AutodeleteClicked,
  119.     8, 15, 264, 112, (UBYTE *)"E_vents in memory:", NULL, GD_Eventlist, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)EventlistClicked,
  120.     76, 130, 60, 13, (UBYTE *)"_Add", NULL, GD_Add, PLACETEXT_IN, NULL, (APTR)AddClicked,
  121.     144, 130, 60, 13, (UBYTE *)"_Remove", NULL, GD_Remove, PLACETEXT_IN, NULL, (APTR)RemoveClicked,
  122.     212, 130, 60, 13, (UBYTE *)"_Update", NULL, GD_Update, PLACETEXT_IN, NULL, (APTR)UpdateClicked,
  123.     16, 151, 117, 13, (UBYTE *)"_Quit, no save", NULL, GD_Cancel, PLACETEXT_IN, NULL, (APTR)CancelClicked,
  124.     148, 151, 117, 13, (UBYTE *)"Quit and _save", NULL, GD_Quit, PLACETEXT_IN, NULL, (APTR)QuitClicked,
  125.     395, 127, 41, 13, NULL, NULL, GD_ShowWDay, 0, NULL, NULL,
  126.     288, 11, 17, 9, NULL, NULL, GD_ARexxMode, PLACETEXT_RIGHT, NULL, (APTR)ARexxModeClicked,
  127.     8, 130, 60, 13, (UBYTE *)"_New", NULL, GD_New, PLACETEXT_IN, NULL, (APTR)NewClicked,
  128.     440, 139, 105, 13, (UBYTE *)"_Month", NULL, GD_Month, PLACETEXT_BELOW, NULL, (APTR)MonthClicked,
  129.     440, 98, 105, 56, NULL, NULL, GD_MonthList, 0, NULL, (APTR)MonthListClicked,
  130.     549, 142, 60, 13, (UBYTE *)"_Year", NULL, GD_Year, PLACETEXT_BELOW, NULL, (APTR)YearClicked,
  131.     419, 58, 54, 13, (UBYTE *)"_Before", NULL, GD_Before, PLACETEXT_LEFT, NULL, (APTR)BeforeClicked,
  132.     555, 58, 54, 13, (UBYTE *)"A_fter", NULL, GD_After, PLACETEXT_LEFT, NULL, (APTR)AfterClicked,
  133.     50, 170, 569, 13, (UBYTE *)"_Text", NULL, GD_Text, PLACETEXT_LEFT, NULL, (APTR)TextClicked,
  134.     381, 21, 231, 12, (UBYTE *)"C_omm/Script", NULL, GD_ARexxCom, PLACETEXT_BELOW, NULL, (APTR)ARexxComClicked,
  135.     512, 7, 100, 12, (UBYTE *)"_Port", NULL, GD_ARexxPort, PLACETEXT_LEFT, NULL, (APTR)ARexxPortClicked,
  136.     396, 142, 41, 13, (UBYTE *)"_Day", NULL, GD_Day, PLACETEXT_BELOW, NULL, (APTR)DayClicked,
  137.     304, 60, 26, 11, (UBYTE *)"_Grouped", NULL, GD_Grouped, PLACETEXT_BELOW, NULL, (APTR)GroupedClicked
  138. };
  139.  
  140. ULONG MainGTags[] = {
  141.     (GTLV_Labels), (ULONG)&Weekday0List, (GTLV_ShowSelected), NULL, (GT_Underscore), '_', (TAG_DONE),
  142.     (GT_Underscore), '_', (TAG_DONE),
  143.     (GTLV_ShowSelected), NULL, (GT_Underscore), '_', (TAG_DONE),
  144.     (GT_Underscore), '_', (TAG_DONE),
  145.     (GT_Underscore), '_', (TAG_DONE),
  146.     (GT_Underscore), '_', (TAG_DONE),
  147.     (GT_Underscore), '_', (TAG_DONE),
  148.     (GT_Underscore), '_', (TAG_DONE),
  149.     (GTTX_Border), TRUE, (TAG_DONE),
  150.     (GTMX_Labels), (ULONG)&ARexxMode0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  151.     (GT_Underscore), '_', (TAG_DONE),
  152.     (GTST_String), (ULONG)"January", (GTST_MaxChars), 9, (GT_Underscore), '_', (TAG_DONE),
  153.     (GTLV_Labels), (ULONG)&MonthList0List, (GTLV_ShowSelected), 1L, (TAG_DONE),
  154.     (GTIN_Number), 0, (GTIN_MaxChars), 4, (GT_Underscore), '_', (TAG_DONE),
  155.     (GTIN_Number), 0, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  156.     (GTIN_Number), 0, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  157.     (GTST_MaxChars), 90, (STRINGA_Justification), (GACT_STRINGCENTER), (GT_Underscore), '_', (TAG_DONE),
  158.     (GTST_MaxChars), 28, (GT_Underscore), '_', (TAG_DONE),
  159.     (GTST_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  160.     (GTIN_Number), 0, (GTIN_MaxChars), 2, (GT_Underscore), '_', (TAG_DONE),
  161.     (GT_Underscore), '_', (TAG_DONE)
  162. };
  163.  
  164. static UWORD ComputeX( UWORD value )
  165. {
  166.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  167. }
  168.  
  169. static UWORD ComputeY( UWORD value )
  170. {
  171.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  172. }
  173.  
  174. static void ComputeFont( UWORD width, UWORD height )
  175. {
  176.     Forbid();
  177.     Font = &Attr;
  178.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  179.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  180.     FontX = GfxBase->DefaultFont->tf_XSize;
  181.     Permit();
  182.  
  183.     OffX = Scr->WBorLeft;
  184.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  185.  
  186.     if ( width && height ) {
  187.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  188.             goto UseTopaz;
  189.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  190.             goto UseTopaz;
  191.     }
  192.     return;
  193.  
  194. UseTopaz:
  195.     Font->ta_Name = (STRPTR)"topaz.font";
  196.     FontX = FontY = Font->ta_YSize = 8;
  197. }
  198.  
  199. int SetupScreen( void )
  200. {
  201.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  202.         return( 1L );
  203.  
  204.     ComputeFont( 0, 0 );
  205.  
  206.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  207.         return( 2L );
  208.  
  209.     return( 0L );
  210. }
  211.  
  212. void CloseDownScreen( void )
  213. {
  214.     if ( VisualInfo ) {
  215.         FreeVisualInfo( VisualInfo );
  216.         VisualInfo = NULL;
  217.     }
  218.  
  219.     if ( Scr        ) {
  220.         UnlockPubScreen( NULL, Scr );
  221.         Scr = NULL;
  222.     }
  223. }
  224.  
  225. void MainRender( void )
  226. {
  227.     struct IntuiText    it;
  228.     UWORD            cnt;
  229.  
  230.     ComputeFont( MainWidth, MainHeight );
  231.  
  232.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 9 ),
  233.                     OffY + ComputeY( 147 ),
  234.                     ComputeX( 264 ),
  235.                     ComputeY( 21 ),
  236.                     GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  237.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  238.                     OffY + ComputeY( 4 ),
  239.                     ComputeX( 341 ),
  240.                     ComputeY( 41 ),
  241.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  242.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  243.                     OffY + ComputeY( 47 ),
  244.                     ComputeX( 341 ),
  245.                     ComputeY( 39 ),
  246.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  247.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 278 ),
  248.                     OffY + ComputeY( 88 ),
  249.                     ComputeX( 341 ),
  250.                     ComputeY( 80 ),
  251.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  252.  
  253.     for ( cnt = 0; cnt < Main_TNUM; cnt++ ) {
  254.         CopyMem(( char * )&MainIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  255.         it.ITextFont = Font;
  256.         it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
  257.         it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
  258.         PrintIText( MainWnd->RPort, &it, 0, 0 );
  259.     }
  260. }
  261.  
  262. int HandleMainIDCMP( void )
  263. {
  264.     struct IntuiMessage    *m;
  265.     int            (*func)();
  266.     BOOL            running = TRUE;
  267.  
  268.     while( m = GT_GetIMsg( MainWnd->UserPort )) {
  269.  
  270.         CopyMem(( char * )m, ( char * )&MainMsg, (long)sizeof( struct IntuiMessage ));
  271.  
  272.         GT_ReplyIMsg( m );
  273.  
  274.         switch ( MainMsg.Class ) {
  275.  
  276.             case    IDCMP_REFRESHWINDOW:
  277.                 GT_BeginRefresh( MainWnd );
  278.                 MainRender();
  279.                 GT_EndRefresh( MainWnd, TRUE );
  280.                 break;
  281.  
  282.             case    IDCMP_CLOSEWINDOW:
  283.                 running = MainCloseWindow();
  284.                 break;
  285.  
  286.             case    IDCMP_VANILLAKEY:
  287.                 running = MainVanillaKey();
  288.                 break;
  289.  
  290.             case    IDCMP_RAWKEY:
  291.                 running = MainRawKey();
  292.                 break;
  293.  
  294.             case    IDCMP_GADGETUP:
  295.             case    IDCMP_GADGETDOWN:
  296.                 func = ( void * )(( struct Gadget * )MainMsg.IAddress )->UserData;
  297.                 running = func();
  298.                 break;
  299.         }
  300.     }
  301.     return( running );
  302. }
  303.  
  304. int OpenMainWindow( void )
  305. {
  306.     struct NewGadget    ng;
  307.     struct Gadget    *g;
  308.     struct TagItem    *tmp;
  309.     UWORD        lc, tc;
  310.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  311.  
  312.     ComputeFont( MainWidth, MainHeight );
  313.  
  314.     ww = ComputeX( MainWidth );
  315.     wh = ComputeY( MainHeight );
  316.  
  317.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  318.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  319.  
  320.     if ( ! ( MainFont = OpenDiskFont( Font )))
  321.         return( 5L );
  322.  
  323.     if ( ! ( g = CreateContext( &MainGList )))
  324.         return( 1L );
  325.  
  326.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  327.  
  328.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  329.  
  330.         ng.ng_VisualInfo = VisualInfo;
  331.         ng.ng_TextAttr   = Font;
  332.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  333.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  334.         ng.ng_Width      = ComputeX( ng.ng_Width );
  335.         ng.ng_Height     = ComputeY( ng.ng_Height);
  336.  
  337.         if ( MainGTypes[ lc ] == LISTVIEW_KIND ) {
  338.             if ( tmp = FindTagItem( GTLV_ShowSelected, ( struct TagItem * )&MainGTags[ tc ] )) {
  339.                 if ( tmp->ti_Data ) tmp->ti_Data = (ULONG)g;
  340.             }
  341.         }
  342.  
  343.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  344.  
  345.         while( MainGTags[ tc ] ) tc += 2;
  346.         tc++;
  347.  
  348.         if ( NOT g )
  349.             return( 2L );
  350.     }
  351.  
  352.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  353.                 WA_Left,    wleft,
  354.                 WA_Top,        wtop,
  355.                 WA_Width,    ww + OffX + Scr->WBorRight,
  356.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  357.                 WA_IDCMP,    LISTVIEWIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|TEXTIDCMP|MXIDCMP|STRINGIDCMP|INTEGERIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  358.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  359.                 WA_Gadgets,    MainGList,
  360.                 WA_Title,    MainWdt,
  361.                 WA_ScreenTitle,    "Reminder V1.20 © 1993 Matti Rintala",
  362.                 TAG_DONE )))
  363.     return( 4L );
  364.  
  365.     GT_RefreshWindow( MainWnd, NULL );
  366.  
  367.     MainRender();
  368.  
  369.     return( 0L );
  370. }
  371.  
  372. void CloseMainWindow( void )
  373. {
  374.     if ( MainWnd        ) {
  375.         CloseWindow( MainWnd );
  376.         MainWnd = NULL;
  377.     }
  378.  
  379.     if ( MainGList      ) {
  380.         FreeGadgets( MainGList );
  381.         MainGList = NULL;
  382.     }
  383.  
  384.     if ( MainFont ) {
  385.         CloseFont( MainFont );
  386.         MainFont = NULL;
  387.     }
  388. }
  389.  
  390.